#include "lib_MonitorProcess.h"
#include <unistd.h>
using namespace std;

vector<string> filter_proc={"systemd","snapfuse","cpptools","node","python","stress-ng"};

class MonitorSystem
{
private:
    MonitorCpu monitor_cpu_impl;
    MonitorMem monitor_mem_impl;
    MonitorProcess monitor_process_impl;
public:
    MonitorSystem()
        :monitor_cpu_impl(), monitor_mem_impl(), monitor_process_impl(&monitor_cpu_impl, &monitor_mem_impl)
    {
    }
    ~MonitorSystem()
    {

    }
    void loop_run()
    {
        uint32_t count = 30;
        sysCpuTime_t* sysCpuTime_data = nullptr;
        sysMem_t* sysMem_data = nullptr;
        allProcessInfo_t* allProcessInfo_data = nullptr;
        allProcessInfo_t* sort_proc = nullptr;
        allProcessInfo_t filter_result;

        while (count--)
        {
            sleep(1);
            sysCpuTime_data = monitor_cpu_impl.updae_cpu_time();
            sysMem_data = monitor_mem_impl.update_sys_mem();
            allProcessInfo_data = monitor_process_impl.update_allProcCpuTime();
            filter_result = monitor_process_impl.filter_proc_by_name(allProcessInfo_data, filter_proc);

            monitor_cpu_impl.show_cpu_usage(sysCpuTime_data);
            monitor_mem_impl.show_sys_mem(sysMem_data);
            // sort_proc = monitor_process_impl.sort_proc_by_cpuUsage(allProcessInfo_data);
            monitor_process_impl.show_allProcessInfo(&filter_result, 0);
        }
    }
};

int main(int argc, char* argv[])
{
    MonitorSystem monitor_system;
    monitor_system.loop_run();
    return 0;
}
